package com.example.demo.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FavouriteMapper {
    @Select("select id from favourite where user_id = #{userId} and item_id = #{itemId}")
    Long selectIdByIds(Long userId, Long itemId);

    @Insert("insert into favourite (user_id, item_id, create_time, update_time) values (#{userId}, #{itemId}, now(), now())")
    boolean addFavourite(Long userId, Long itemId);

    @Select("select item_id from favourite where user_id = #{userId} order by id desc")
    List<Long> selectItemIdByUserId(Long userId);

    @Delete("delete from favourite where user_id = #{userId} and item_id = #{itemId}")
    boolean deleteFavourite(Long userId, Long itemId);
}
